/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SpelFrame.java
 *
 * Created on 13-jun-2010, 22:27:21
 */
package View;

import cradleofrome.*;
import java.awt.event.*;

/**
 *
 * @author Tim
 */
public class SpelFrame extends javax.swing.JFrame {

    private Spelveld spelveld1;
    private String richting;

    /** Creates new form SpelFrame */
    public SpelFrame() {

        spelveld1 = new Spelveld(10, 10, 25);
        initComponents();
        spelPanel.requestFocus();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        buttonPanel = new javax.swing.JPanel();
        resetButton = new javax.swing.JButton();
        closeButton = new javax.swing.JButton();
        spelPanel = new SpelPanel(spelveld1);

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cradle of Rome");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        buttonPanel.setPreferredSize(new java.awt.Dimension(100, 250));

        resetButton.setText("Reset");
        resetButton.setToolTipText("Reset the game");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        closeButton.setText("Close");
        closeButton.setToolTipText("Close the game");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
        buttonPanel.setLayout(buttonPanelLayout);
        buttonPanelLayout.setHorizontalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(resetButton, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                    .addComponent(closeButton, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                .addContainerGap())
        );
        buttonPanelLayout.setVerticalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(resetButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(closeButton)
                .addContainerGap(286, Short.MAX_VALUE))
        );

        getContentPane().add(buttonPanel, java.awt.BorderLayout.EAST);

        spelPanel.setBackground(new java.awt.Color(255, 255, 255));
        spelPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        spelPanel.setPreferredSize(new java.awt.Dimension(250, 250));
        spelPanel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                spelPanelKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout spelPanelLayout = new javax.swing.GroupLayout(spelPanel);
        spelPanel.setLayout(spelPanelLayout);
        spelPanelLayout.setHorizontalGroup(
            spelPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 417, Short.MAX_VALUE)
        );
        spelPanelLayout.setVerticalGroup(
            spelPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 345, Short.MAX_VALUE)
        );

        getContentPane().add(spelPanel, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
/*
     * event handler voor startButton
     */    /*
     * keyevent handler voor het opvangen van de toetsaanslagen
     */
    private void spelPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_spelPanelKeyPressed
        switch (evt.getKeyCode()) {

            case KeyEvent.VK_LEFT:
                richting = "links";
                move(richting);
                break;
            case KeyEvent.VK_RIGHT:
                richting = "rechts";
                move(richting);
                break;
            case KeyEvent.VK_UP:
                richting = "boven";
                move(richting);
                break;
            case KeyEvent.VK_DOWN:
                richting = "beneden";
                move(richting);
                break;
        }
    }//GEN-LAST:event_spelPanelKeyPressed

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed

        System.exit(0);
    }//GEN-LAST:event_closeButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed

       
    }//GEN-LAST:event_resetButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SpelFrame().setVisible(true);
            }
        });
    }
    /*
     * aansturen van de selector doormiddel van de methode aan te roepen
     * @param String richting
     */

    private void move(String richting) {

        Selector selektor = spelveld1.getSelector();
        System.out.println("moved to " + richting + " is " + selektor.move(richting));
        System.out.println("current position is Y: " + (selektor.getPositie()).getY() + " X: " + (selektor.getPositie()).getX());
        spelPanel.repaint();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton closeButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton resetButton;
    private javax.swing.JPanel spelPanel;
    // End of variables declaration//GEN-END:variables
}
